package com.qf.agro.controller.sys;

import com.qf.agro.common.ResultInfo;
import com.qf.agro.common.SysUserHolder;
import com.qf.agro.pojo.SysModule;
import com.qf.agro.pojo.SysUser;
import com.qf.agro.service.sys.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/sys/module")
public class ModelController {

    @Autowired
    private ModelService modelService;

    /**
     * 查询当前用户菜单列表
     * @return
     */
    @GetMapping("/menu")
    public ResultInfo findMenuList() {
        //1. 获取当前登录用户id信息
        SysUser sysUser = SysUserHolder.get();
        if(sysUser == null) {
            return ResultInfo.error("非法用户, 请从新登录!");
        }
        Long userId = sysUser.getId();

        //2. 根据当前登录用户id, 查询对应的菜单列表
        List<SysModule> list = modelService.findMenuAll(userId);
        //3. 封装数据返回
        return ResultInfo.success(list);
    }
}
